import 'package:flutter/material.dart';
import 'package:flutter_demo_app/componet/icon_tab.dart';

class tabBarPage extends StatefulWidget {
  tabBarPage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  State<StatefulWidget> createState() => tabBarPageState();
}

const double _kTabTextSize = 11.0;
const int INDEX_0 = 0;
const int INDEX_1 = 1;
const int INDEX_2 = 2;
const int INDEX_3 = 3;
const int INDEX_4 = 4;

class tabBarPageState extends State<tabBarPage>
    with SingleTickerProviderStateMixin {
  int _currentIndex = 0;
  TabController _controller;
  VoidCallback onChanged;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller =
        new TabController(initialIndex: _currentIndex, length: 4, vsync: this);
    onChanged = () {
      _currentIndex = this._controller.index;
    };

    _controller.addListener(onChanged);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: new TabBarView(
        children: <Widget>[],
        controller: _controller,
      ),
      bottomNavigationBar: new Material(
        color: Colors.white,
        child: TabBar(tabs: <IconTab>[
          //自己封装的IconTab组件

          new IconTab(
            icon: _currentIndex == INDEX_0
                ? "assets/images/ic_mic.png"
                : "assets/images/ic_pause.png",
            text: "ssss",
            color: _currentIndex == INDEX_0 ? Colors.green : Colors.orange,
          ),
          new IconTab(
            icon: _currentIndex == INDEX_1
                ? "assets/images/ic_mic.png"
                : "assets/images/ic_pause.png",
            text: "ssss",
            color: _currentIndex == INDEX_1 ? Colors.green : Colors.orange,
          ),
          new IconTab(
            icon: _currentIndex == INDEX_2
                ? "assets/images/ic_mic.png"
                : "assets/images/ic_pause.png",
            text: "ssss",
            color: _currentIndex == INDEX_2 ? Colors.green : Colors.orange,
          ),
          new IconTab(
            icon: _currentIndex == INDEX_3
                ? "assets/images/ic_mic.png"
                : "assets/images/ic_pause.png",
            text: "ssss",
            color: _currentIndex == INDEX_3 ? Colors.green : Colors.orange,
          ),
        ]),
      ),
    );
  }
}
